package com.ymatou.iapi.im.testcase;

import com.ymatou.iapi.im.parameter.*;
import com.ymatou.iapi.im.service.GetMessageCountCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymttest.business.service.ImCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import java.util.List;
import java.util.Map;

/**
*获取消息未读数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetMessageCount{
	private static GetMessageCountBean getmessagecountBean;
	private static GetMessageCountCall getmessagecountCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取消息未读数");
	}

	@Before
	public void caseUp() {
		getmessagecountBean=new GetMessageCountBean();
		getmessagecountCall=new GetMessageCountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getmessagecountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMessageCount_01() {
		Logger.start(true,"获取消息未读数，买家给买手发送消息");
		try {
			UserRegisterInfoRequestDtoBean regbean1 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoBean regbean2 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc1 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean1);
			UserRegisterInfoRequestDtoCall urrc2 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean2);
			Integer userId = urrc1.getUserid();
			Integer fromUserId = urrc2.getUserid();
			SendMessageToSellerBean sendMessageToSellerBean = ImCallService.initSendMessageToSellerBean(userId,fromUserId,"我是买家");
			ImCallService.SendMessageToSeller(sendMessageToSellerBean);
			ImCallService.SendMessageToSeller(sendMessageToSellerBean);
			ImCallService.SendMessageToSeller(sendMessageToSellerBean);
			List<Map> map = new ImDefaultWapper().selectTotalCount(userId,fromUserId);
			Logger.debug(map);
			getmessagecountBean.setUserId(fromUserId);
			getmessagecountCall.setData(getmessagecountBean);
			getmessagecountCall.callService();
			Logger.verifyEquals("Success",getmessagecountCall.getString("Status"),"验证Status");
			Logger.verifyEquals(Integer.parseInt(getmessagecountCall.getString("Result")),Integer.parseInt(map.get(0).get("UnReadCount").toString()),"验证未读数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMessageCount_02() {
		Logger.start(true,"获取消息未读数，买家给码头洋洋发送消息");
		try {
			UserRegisterInfoRequestDtoBean regbean1 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoBean regbean2 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc1 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean1);
			UserRegisterInfoRequestDtoCall urrc2 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean2);
			Integer userId = urrc1.getUserid();
			Integer fromUserId = urrc2.getUserid();
			SendMessageBean sendMessage = ImCallService.initSendMessage(userId,fromUserId,"我是买家");
			ImCallService.SendMessage(sendMessage);
			ImCallService.SendMessage(sendMessage);
			ImCallService.SendMessage(sendMessage);
			List<Map> map = new ImDefaultWapper().selectTotalCount(userId,fromUserId);
			Logger.debug(map);
			getmessagecountBean.setUserId(fromUserId);
			getmessagecountCall.setData(getmessagecountBean);
			getmessagecountCall.callService();
			Logger.verifyEquals("Success",getmessagecountCall.getString("Status"),"验证Status");
			Logger.verifyEquals(Integer.parseInt(getmessagecountCall.getString("Result")),Integer.parseInt(map.get(0).get("UnReadCount").toString()),"验证未读数");
			GetMessageListAndSessionByTimelineBean getMessageListAndSessionByTimelineBean = ImCallService.initGetMessageListAndSessionByTimelineBean(fromUserId,userId);
			ImCallService.GetMessageListAndSessionByTimeline(getMessageListAndSessionByTimelineBean);
			getmessagecountCall.callService();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMessageCount_03() {
		Logger.start(true,"获取消息未读数，买手给买家发送消息");
		try {
			UserRegisterInfoRequestDtoBean regbean1 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoBean regbean2 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc1 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean1);
			UserRegisterInfoRequestDtoCall urrc2 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean2);
			Integer userId = urrc1.getUserid();
			Integer fromUserId = urrc2.getUserid();
			SendMessageToBuyerBean sendMessage = ImCallService.initSendMessageToBuyerBean(userId,fromUserId,"我是买家");
			ImCallService.SendMessageToBuyer(sendMessage);
			ImCallService.SendMessageToBuyer(sendMessage);
			ImCallService.SendMessageToBuyer(sendMessage);
			List<Map> map = new ImDefaultWapper().selectTotalCount(userId,fromUserId);
			Logger.debug(map);
			getmessagecountBean.setUserId(fromUserId);
			getmessagecountCall.setData(getmessagecountBean);
			getmessagecountCall.callService();
			Logger.verifyEquals("Success",getmessagecountCall.getString("Status"),"验证Status");
			Logger.verifyEquals(Integer.parseInt(getmessagecountCall.getString("Result")),Integer.parseInt(map.get(0).get("UnReadCount").toString()),"验证未读数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMessageCount_04() {
		Logger.start(true,"获取消息未读数，用户id不正确");
		try {
			getmessagecountBean.setUserId(-1);
			getmessagecountCall.setData(getmessagecountBean);
			getmessagecountCall.callService();
			Logger.verifyEquals("ParameterError",getmessagecountCall.getString("Status"),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMessageCount_05() {
		Logger.start(true,"获取消息未读数，用户不存在");
		try {
			getmessagecountBean.setUserId(000123);
			getmessagecountCall.setData(getmessagecountBean);
			getmessagecountCall.callService();
			Logger.verifyEquals("BussinessError",getmessagecountCall.getString("Status"),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


}